<template>
	<view class="toast-item" :class="{'red': toastData.type === 'danger'}" @tap.stop="itemClick">
		<view class="toast-imgs" v-if="toastData.imgs && toastData.imgs.length > 0">
			<view v-if="toastData.imgs[2]">
				<image class="toast-img toast-img3" :src="toastData.imgs[2]"></image>
				<view class="imgs-fill-shim"></view>
			</view>

			<view v-if="toastData.imgs[1]">
				<image class="toast-img toast-img2" :src="toastData.imgs[1]"></image>
				<view class="imgs-fill-shim"></view>
			</view>

			<view v-if="toastData.imgs[0]">
				<image class="toast-img toast-img1" :src="toastData.imgs[0]"></image>
				<view class="imgs-fill"></view>
			</view>
		</view>

		<image class="success-icon" v-if="!toastData.imgs && toastData.type === 'success'"
			src="../../static/successIconWhite.png"></image>
			
		<view class="toast-text">{{toastData.text}}</view>
	</view>
</template>

<script>
	export default {
		props: {
			toastData: {
				type: Object,
				default: () => {
					return {}
				}
			}
		},
		methods: {
			cleanTimer() {
				if (this.timer) {
					clearTimeout(this.timer)
					this.timer = null
				}
			},
			itemClick() {
				this.$emit('itemClk', this.toastData)
			}
		},
		mounted() {
			this.timer = setTimeout(() => {
				this.$emit('close', this.toastData.id)
				this.cleanTimer()
			}, this.toastData.duration || 1500)
		},
		beforeDestroy() {
			this.cleanTimer()
		}

	}
</script>

<style lang="less" scoped>
	.toast-item {
		padding: 12rpx;
		padding-right: 26rpx;
		box-sizing: border-box;
		margin-bottom: 22rpx;
		height: 84rpx;
		border-radius: 42rpx;
		background-color: rgba(51, 153, 255, 0.8);
		display: flex;
		align-items: center;

		&.red {
			background-color: rgba(255, 76, 76, 0.8);
		}

		.toast-imgs {
			display: flex;
			position: relative;


			.toast-img {
				position: absolute;
				top: 0;
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
			}

			.toast-img1 {
				right: 0;
			}

			.toast-img2 {
				right: 16rpx;
			}

			.toast-img3 {
				right: 32rpx;
			}

			.imgs-fill {
				width: 60rpx;
				height: 60rpx;
			}

			.imgs-fill-shim {
				width: 16rpx;
				height: 60rpx;
			}
		}

		.success-icon {
			margin-left: 14rpx;
			width: 34rpx;
			height: 34rpx;
		}

		.toast-text {
			margin-left: 14rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 40rpx;
		}
	}
</style>
